package com.ymatou.iapi.accounting.service;

import org.json.JSONException;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ymatou.iapi.accounting.parameter.AccountEntryBean;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.Logger;
import com.ymttest.utils.EnvSetup;
/**
*获取账户资金流水接口Call
*FreeMaker Template自动生成代码
*/
public class GetAccountEntryCall extends YmatouBaseCall{
	private static String opurl ="api/Account/GetAccountEntry";
	
	public GetAccountEntryCall() {
		super(EnvSetup.getSystemUrl("accounting_iapi"),opurl,"POST","JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept","text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}
	
	//get statuscode
			public int getStatuscode(){
				int status=0;
				try {
					status = new JSONObject(getReturnData()).getInt("StatusCode");
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return status;
				
			}	
			
			//get msg
			public String getMsg(){
				String msg=null;
				try {
					msg = new JSONObject(getReturnData()).getString("Message");
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return msg;				
			}				
			//get data
			public JSONObject getData(){
				JSONObject data=null;		
				 try {
					data=new JSONObject(getReturnData()).getJSONObject("Data");
					} catch (JSONException e) {
						Logger.debug("Ts_GetAccountEntryList return data is null!");
					}
				 return data;	
			}
			//get the return account info list
			public AccountEntryBean  getReturnAccountEntry() throws JSONException{
				AccountEntryBean  entry = null;		
				String data = getData().toString();
				if (data!=null){			
					Gson gson = new Gson();
					entry = gson.fromJson(data, new TypeToken<AccountEntryBean>() {
					}.getType());
				}
				return entry;
			}	
			
			
}